/**
 * Maybe 函子
 */
class Maybe {

    static of (value) {
        return new Maybe(value)
    }

    constructor (value) {
        this._value = value
    }

    map (fn) {

        return this.isNULL() ? Maybe.of(null) : 
                (this.isUndefined() ? Maybe.of(undefined) : Maybe.of(fn(this._value)))
    }

    // null的情况
    isNULL () {
        return this._value === null
    }

    // undefined的情况
    isUndefined () {
        return this._value === undefined
    }
}

/**
 * Container 函子
 */
class Container {

    static of (value) {
        return new Container(value)
    }

    constructor (value) {
        this._value = value
    }

    map (fn) {
        return  Container.of(fn(this._value))
    }
}

module.exports = { Maybe, Container} 